package com.hardy.leecode;

import java.util.HashSet;
import java.util.Set;

/**
 * Author: Hardy
 * Date:   2020/12/14
 * Description:
 **/
public class QueOffer48 {
    public static void main(String[] args) {
        /**
         *
         */
        System.out.println(new Solution().lengthOfLongestSubstring("pwwkew"));
    }

    static class Solution {

        public int lengthOfLongestSubstring(String s) {
            int i = 0, j = 0, v = 0;
            Set<Character> set = new HashSet<>();

            for (; j < s.length(); j++) {
                char c = s.charAt(j);
                if (set.contains(c)) {
                    v = Math.max(v, j - i);
                    while (s.charAt(i) != c) set.remove(s.charAt(i++));
                    i++;
                } else {
                    set.add(c);
                }
            }
            v = Math.max(v, j - i);
            return v;
        }
        // abba i++
        // abb  i++ i++
    }
}
